package com.mrx.spring.security.advice;

import com.mrx.commons.model.dto.Result;
import com.mrx.spring.security.exception.SecurityException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 安全框架全局异常处理
 *
 * @author Mr.X
 * @since 2023-10-16 15:46
 **/
@RestControllerAdvice("com.mrx.spring.security")
public class SecurityAdvice {

    private static final Logger logger = LoggerFactory.getLogger(SecurityAdvice.class);

    @ExceptionHandler(SecurityException.class)
    public Result<?> securityExceptionHandler(SecurityException exception) {
        String message = exception.getMessage();
        logger.debug("handle exception: {}", message);
        return Result.fail(message);
    }

}
